import Mock from 'mockjs'
// import config from '../../config'

// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context("./modules", true, /\.js$/);

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
modulesFiles.keys().reduce((modules, modulePath) => {
  // const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
  const value = modulesFiles(modulePath);
  const module = value.default;
  Object.values(module).forEach(m => {
    // const url = `${config.baseURL}:${config.port}${m.url}`
    Mock.mock(m.url,m.type,
      (opts) => {
        console.log('\n')
        console.log('%cmock拦截, 请求: ', 'color:blue', opts)
        console.log('%cmock拦截, 响应: ', 'color:blue', m.data)
        return m.data
      }
    )

  })
}, {});
